<?php include './view/htm/header.inc.htm'; ?>

<div class="row">
	<div class="col-lg-10 col-lg-offset-1">
		<div class="btn-group m-b-1" role="group">
			<?php echo admin_tab_active($menu['setting']['tab'], 'smtp');?>
		</div>
		<div class="card">
			<div class="card-block">
				<form action="<?php echo url('setting-smtp');?>" method="post" id="form">
					<h4 class="card-title"><?php echo lang('admin_setting_smtp');?></h4>
					<div class="table-responsive arrlist">
						<table class="table"  style="min-width: 800px">
							<thead>
								<tr align="center">
									<th><?php echo lang('group_name');?></th>
									<th><?php echo lang('admin_setting_smtp');?></th>
									<th width="100" class="text-center"><?php echo lang('port');?></th>
									<th class="text-center"><?php echo lang('account');?></th>
									<th class="text-center"><?php echo lang('password');?></th>
									<th class="text-center"><?php echo lang('delete');?></th>
								</tr>
							<thead>
							<tbody>
								<?php foreach($smtplist as $rowid=>$smtp) { ?>
								<tr align="center" rowid="<?php echo $rowid; ?>">
									<td><input type="text" class="form-control" name="email[]" value="<?php echo $smtp['email']; ?>" placeholder="<?php echo lang('email');?>" /></td>
									<td><input type="text" class="form-control" name="host[]" value="<?php echo $smtp['host']; ?>"  placeholder="<?php echo lang('host');?>" /></td>
									<td><input type="text" class="form-control" name="port[]" value="<?php echo $smtp['port']; ?>" placeholder="<?php echo lang('port');?>"/></td>
									<td><input type="text" class="form-control" name="user[]" value="<?php echo $smtp['user']; ?>" placeholder="<?php echo lang('username');?>"  /></td>
									<td><input type="text" class="form-control" name="pass[]" value="<?php echo $smtp['pass']; ?>" placeholder="<?php echo lang('password');?>"  /></td>
									<td><a class="btn row_delete" role="btn"><?php echo lang('delete');?></a></td>
								</tr>
								<?php } ?>
							</tbody>
						</table>
					</div>
					<p><a role="button" class="btn row_add">[+]<?php echo lang('add_new_line');?></a></p>
					<p class="text-center">
						<button type="submit" class="btn btn-primary" id="submit" data-loading-text="<?php echo lang('submiting');?>..." style="width: 10rem;"><?php echo lang('confirm');?></button>
					</p>
				</form>
			</div>
		</div>
	</div>
</div>

<?php include './view/htm/footer.inc.htm'; ?>

<script>

var jform = $("#form");
var jsubmit = $("#submit");
jform.on('submit', function(){
	jform.reset();
	jsubmit.button('loading');
	var postdata = jform.serialize();
	$.xpost(jform.attr('action'), postdata, function(code, message) {
		if(code == 0) {
			$.alert(message);
			jsubmit.text(message).delay(1000).button('reset');
			return;
		} else {
			alert(message);
			jsubmit.button('reset');
		}
	});
	return false;
});

// 删除 delete
var jarrlist = $('.arrlist');
var jdelete = $('a.row_delete');
jarrlist.on('click', 'a.row_delete', function() {
	var jthis = $(this);
	var jtr = jthis.parents('tr');
	var rowid = jtr.attr('rowid');
	jtr.remove();
	return false;
});

// 增加 add
var jadd = $('a.row_add');
jadd.on('click', function() {
	var jclone = jarrlist.find('tr').last().clone();
	jclone.insertAfter(jarrlist.find('tr').last());
	return false;
});


$('#nav_pc li.setting, #nav_mobile li.setting').tab('show');

</script>